<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\Auth\User;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->string('name', 50)->comment('名称');
            $table->string('username', 50)->unique()->comment('登录账号');
            $table->string('password')->comment('登录密码');
            $table->string('contact', 100)->default('')->comment('联系方式');
            $table->boolean('banned')->default(false)->comment('是否禁用');
            $table->string('identity', 50)->default('')->comment('身份类型');
            $table->boolean('super')->default(false)->comment('是否为身份总管理员');
            $table->unsignedBigInteger('lst_login_ip')->default(0)->comment('登录IP');
            $table->timestamp('lst_login_at')->nullable()->comment('登录时间');
            $table->string('remark')->default('')->comment('备注');
            $table->unsignedInteger('level')->default(0)->comment('层级');
            $table->timestamps();
        });
        DB::statement("alter table `users` comment '后台用户';");

        $admin = new User([
            'name' => '超级管理员',
            'username' => 'superadmin',
            'password' => bcrypt('superadmin123456'),
            'super' => true,
            'identity' => User::IDENTITY_SYSTEM,
            'remark' => '系统创建',
            'level' => 0
        ]);

        $admin->save();

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
